<?php
// +----------------------------------------------------------------------
// | UBTEN.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.taodudu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------
namespace User\Controller;
use User\Controller\BaseController;

class CollectionController extends BaseController {
    
    
    public function index(){
        //商品收藏
        $favorites = M('Favorites');
        $fav = $favorites->where(array('user_id'=>session('user_id'),'fav_type'=>20))->select();
        if($fav){
            foreach ($fav as $key => $value) {
                $fav[$key]['goods'] = M('goods')->where('goods_id='.$value['goods_id'])->find();
            }
        }
        $this->assign('fav', $fav);
        $this->assign('active','collection');
        $this->display();
    }
    
    public function supplier(){
        $favorites = M('Favorites');
        $fav = $favorites->where(array('user_id'=>session('user_id'),'fav_type'=>40))->select();
        if($fav){
            foreach ($fav as $key => $value) {
                $fav[$key]['store'] = M('store')->where('store_id='.$value['goods_id'])->find();
            }
        }
        $this->assign('fav', $fav);
        $this->assign('active','supplier');
        $this->display();
    }

    

    //删除收藏/取消关注
    public function delColl(){
        $where['fav_id'] = I('post.fav_id');
        $favorites = M('Favorites')->where($where)->delete();
        if($favorites){
            $this->success('取消成功！');
        }else{
            $this->error('网络链接失败！');
        }
    }
}



